package com.marvels.approve.mqueues.service.hystrix;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.marvels.approve.common.dto.LoanApplyContactInfoDTO;
import com.marvels.approve.common.dto.LoanExtInfoDTO;
import com.marvels.approve.loan.dto.McamAcLoanApplyBdInfo;
import com.marvels.approve.loan.dto.McamAcLoanApplyImageInfo;
import com.marvels.approve.loan.dto.McamLoanApplyInfoDTO;
import com.marvels.approve.mqueues.service.ApproveLoanApplySynchronizeApi;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.dubbo.coreservice.service.ILoanApplyInfoService;

@Service
public class LoanApplySynchronizeFeignService implements ApproveLoanApplySynchronizeApi {

	@Autowired
	private ILoanApplyInfoService loanApplyInfoService;
	
	@Override
	public McamLoanApplyInfoDTO queryLoanBasicInfo(String loanId) {
		try {
			com.dragon.loan.entity.McamLoanApplyInfo apiResult = loanApplyInfoService.findLoanApplyInfo(loanId);
			McamLoanApplyInfoDTO result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), McamLoanApplyInfoDTO.class);
			MarvelsLogUtil.getInstance().info("ApproveLoanApplySynchronizeApi.queryLoanBasicInfo direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveLoanApplySynchronizeApi.queryLoanBasicInfo error", e);
			return null;
		}
	}

	@Override
	public List<McamAcLoanApplyBdInfo> queryApplyInfo(String loanId) {
		try {
			List<com.dragon.loan.entity.McamAcLoanApplyBdInfo> apiResult = loanApplyInfoService.findLoanApplyBdInfo(loanId);
			List<McamAcLoanApplyBdInfo> result = JSONObject.parseArray(JSONObject.toJSONString(apiResult), McamAcLoanApplyBdInfo.class);
			MarvelsLogUtil.getInstance().info("ApproveLoanApplySynchronizeApi.queryApplyInfo direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveLoanApplySynchronizeApi.queryApplyInfo error", e);
			return null;
		}
	}

	@Override
	public List<McamAcLoanApplyImageInfo> queryImageInfo(String caseId) {
		try {
			List<com.dragon.loan.entity.McamAcLoanApplyImageInfo> apiResult = loanApplyInfoService.findLoanApplyImageInfo(caseId);
			List<McamAcLoanApplyImageInfo> result = JSONObject.parseArray(JSONObject.toJSONString(apiResult), McamAcLoanApplyImageInfo.class);
			MarvelsLogUtil.getInstance().info("ApproveLoanApplySynchronizeApi.queryImageInfo direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveLoanApplySynchronizeApi.queryImageInfo error", e);
			return null;
		}
	}

	@Override
	public List<LoanApplyContactInfoDTO> queryLinkmanList(String loanId) {
		try {
			List<com.marvels.dubbo.coreservice.controller.LoanApplyContactInfoDTO> apiResult= loanApplyInfoService.queryLinkmanList(loanId);
			List<LoanApplyContactInfoDTO> result = JSONObject.parseArray(JSONObject.toJSONString(apiResult), LoanApplyContactInfoDTO.class);
			MarvelsLogUtil.getInstance().info("ApproveLoanApplySynchronizeApi.queryLinkmanList direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveLoanApplySynchronizeApi.queryLinkmanList error", e);
			return null;
		}
	}

	@Override
	public LoanExtInfoDTO queryExtInfo(String loanId) {
		try {
			com.marvels.dubbo.coreservice.dto.LoanExtInfoDTO apiResult = loanApplyInfoService.queryExtInfoByLoanId(loanId);
			LoanExtInfoDTO result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), LoanExtInfoDTO.class);
			MarvelsLogUtil.getInstance().info("ApproveLoanApplySynchronizeApi.queryExtInfo direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveLoanApplySynchronizeApi.queryExtInfo error", e);
			return null;
		}
	}

	@Override
	public void updateLoanMoneyAct(String loanId, String loanMoneyAct) {
		try {
			loanApplyInfoService.updateLoanMoneyAct(loanId, loanMoneyAct);
			MarvelsLogUtil.getInstance().info("ApproveLoanApplySynchronizeApi.updateLoanMoneyAct direct call success!");
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveLoanApplySynchronizeApi.updateLoanMoneyAct error", e);
		}
	}

	@Override
	public void loanNodeFlow(String loanId, String result) {
		try {
			loanApplyInfoService.loanNodeFlow(loanId, result);
			MarvelsLogUtil.getInstance().info("ApproveLoanApplySynchronizeApi.loanNodeFlow direct call success!");
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveLoanApplySynchronizeApi.loanNodeFlow error", e);
		}
	}

}
